package com.pentakill.mo.essay.essay.business.ebo;

import java.io.Serializable;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.pentakill.mo.auth.user.vo.UserModel;
import com.pentakill.mo.essay.discuss.business.ebi.DiscussEbi;
import com.pentakill.mo.essay.discuss.vo.DiscussModel;
import com.pentakill.mo.essay.essay.business.ebi.EssayEbi;
import com.pentakill.mo.essay.essay.dao.dao.EssayDao;
import com.pentakill.mo.essay.essay.vo.EssayModel;
import com.pentakill.mo.util.base.BaseQueryModel;
@Transactional
public class EssayEbo implements EssayEbi {
	
	private EssayDao essayDao;
	private DiscussEbi discussEbi;
	
	
	public void setDiscussEbi(DiscussEbi discussEbi) {
		this.discussEbi = discussEbi;
	}

	public void setEssayDao(EssayDao essayDao) {
		this.essayDao = essayDao;
	}

	public void save(EssayModel em) {
		em.setCreateDate(System.currentTimeMillis());
		em.setStatus(EssayModel.STATUS_AUDITING);
		essayDao.add(em);
	}

	public List<EssayModel> getAll() {
		return essayDao.getAll();
		
	}

	public EssayModel get(Serializable uuid) {
		
		return essayDao.get(uuid);
	}

	public void update(EssayModel t) {
		// TODO Auto-generated method stub
		
	}

	public void delete(EssayModel t) {
		// TODO Auto-generated method stub
		
	}

	public List<EssayModel> getAll(BaseQueryModel dqm, Integer pageNum, Integer pageCount) {
		// TODO Auto-generated method stub
		return null;
	}

	public Integer getCount(BaseQueryModel dqm) {
		// TODO Auto-generated method stub
		return null;
	}
	//创建评论
	public void createDiscuss(UserModel user,Integer uuid, DiscussModel dm) {
		EssayModel essay = get(uuid);
		dm.setEssayModel(essay);
		dm.setCreateDate(System.currentTimeMillis());
		dm.setUserModels(user);
		//没有设置为0
		dm.setParent(null);
		discussEbi.save(dm);
	}

	public void replyDiscuss(UserModel user, Integer uuid, DiscussModel dm) {
		EssayModel essay = get(uuid);
		dm.setEssayModel(essay);
		dm.setCreateDate(System.currentTimeMillis());
		dm.setUserModels(user);
		
		//手动查询父评论
		DiscussModel parent = discussEbi.get(dm.getUuid());
		
		
		dm.setParent(parent);
		dm.setUuid(null);
		
		discussEbi.save(dm);
	}
	

	public void update(EssayModel em, Integer status) {
		EssayModel temp = essayDao.get(em.getUuid());
		temp.setStatus(status);
		
	}

	public List<EssayModel> getShowPassLlis(BaseQueryModel eqm, Integer pageNum, Integer pageCount) {
		return essayDao.getShowPassLlis(eqm, pageNum, pageCount);
	}

	public EssayModel getByPass(BaseQueryModel eqm) {
		return essayDao.getByPass(eqm);
	}

	public int getPassCount(BaseQueryModel eqm) {
		return essayDao.getPassCount(eqm);
	}

}
